//一棵圣诞树记作根节点为 root 的二叉树，节点值为该位置装饰彩灯的颜色编号。请按照从左到右的顺序返回每一层彩灯编号，每一层的结果记录于一行。 
//
// 
//
// 示例 1： 
//
// 
//
// 
//输入：root = [8,17,21,18,null,null,6]
//输出：[[8],[17,21],[18,6]]
// 
//
// 提示： 
//
// 
// 节点总数 <= 1000 
// 
//
// 注意：本题与主站 102 题相同：https://leetcode-cn.com/problems/binary-tree-level-order-
//traversal/ 
//
// 
//
// Related Topics 树 广度优先搜索 二叉树 👍 323 👎 0


package LeetCode.editor.cn;


import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;

/**
 * @author ldltd
 * @date 2025-05-08 16:58:13
 * @description LCR 150.彩灯装饰记录 II
 
 */
 
public class CongShangDaoXiaDaYinErChaShuIiLcof {
    public static void main(String[] args) {
    //测试代码
    CongShangDaoXiaDaYinErChaShuIiLcof fun = new CongShangDaoXiaDaYinErChaShuIiLcof();
    Solution solution= fun.new Solution();
    
    }

//leetcode submit region begin(Prohibit modification and deletion)

//  Definition for a binary tree node.
  public class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
         this.val = val;
          this.left = left;
          this.right = right;
      }
  }

class Solution {
    public List<List<Integer>> decorateRecord(TreeNode root) {

            if(root==null) return new ArrayList<>();
            Deque<TreeNode> q=new ArrayDeque<>();
            q.offer(root);
            List<List<Integer>> res=new ArrayList<>();
            while (!q.isEmpty()){
                int n=q.size();
                List<Integer> t=new ArrayList<>();
                while (n>0){
                    TreeNode poll = q.poll();
                    t.add(poll.val);
                    if(poll.left!=null) q.offer(poll.left);
                    if(poll.right!=null) q.offer(poll.right);
                    n--;
                }
                res.add(t);
            }
            return res;

    }
}
//leetcode submit region end(Prohibit modification and deletion)

}
